from direct.gui.DirectGui import DirectFrame, DirectLabel
from Cube.gui.QSizer import ResizedCallBackSet, BoxSizer
from Cube.gui.DirectGUIPropertiesAccess import AlignText

MapNameTextScale = 0.08
MapInfoTextScale = 0.07

DefaultParameter_MiniatureImg = dict(
    frameSize = (-0.3, 0.3, -0.3, 0.3),
    #color = (0.2,0,0)
    #image = "Cube/gui/GameLobby/panda3d.png",
)

DefaultParameter_MapNameText = dict(
    frameSize = (-1.2, 1.2, -0.05, 0.05),
    text = "Map Name",
    text_scale = MapNameTextScale
)

DefaultParameter_MapInfoText = dict(
    text = "Map Info",
    text_scale = MapInfoTextScale
)

class MapInfoFrame(DirectFrame):
    def __init__(self,
                 parent = None,
                 miniatureInfo = {},
                 mapNameInfo = {},
                 mapInfoInfo = {},
                 mapInfoData = None  # Cube.map.QMapHeader.QMapInfo
                ):
        DirectFrame.__init__(self, parent)

        paramIn_MiniatureImg = DefaultParameter_MiniatureImg.copy()
        paramIn_MiniatureImg.update(miniatureInfo)
        paramIn_MiniatureImg["parent"] = self
        paramIn_MapNameText = DefaultParameter_MapNameText.copy()
        paramIn_MapNameText.update(mapNameInfo)
        paramIn_MapNameText["parent"] = self
        paramIn_MapInfoText = DefaultParameter_MapInfoText.copy()
        paramIn_MapInfoText.update(mapInfoInfo)
        paramIn_MapInfoText["parent"] = self

        if mapInfoData:
            # Cube.map.QMapHeader.QMapInfo
            paramIn_MapNameText["text"] = mapInfoData.Name
            paramIn_MapInfoText["text"] = mapInfoData.Info

        img_Miniature = DirectLabel(**paramIn_MiniatureImg)
        txt_MapName = DirectLabel(**paramIn_MapNameText)
        txt_MapInfo = DirectLabel(**paramIn_MapInfoText)

        sizerMapInfo = BoxSizer(BoxSizer.VERTICAL, gap = 0.01)
        sizerMapInfo.Add(txt_MapName,0)
        sizerMapInfo.Add(txt_MapInfo,1)
        sizerMain = BoxSizer(BoxSizer.HORIZONTAL, gap = 0.02)
        sizerMain.Add(img_Miniature, 0)
        sizerMain.Add(sizerMapInfo, 1)
        sizerMain.Attach2Frame(self)

        ResizedCallBackSet(txt_MapName, AlignText, frame = txt_MapName, align = "left" )
        ResizedCallBackSet(txt_MapInfo, AlignText, frame = txt_MapInfo, align = "left,top" )
